package com.controller;



import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import com.beans.Account;
import com.beans.User;
import com.dto.Result;
import com.dto.SignUpDTO;
import com.server.AccountService;
import lombok.extern.slf4j.Slf4j;
import javax.annotation.Resource;
import javax.servlet.http.HttpSession;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 古嘉琦
 * @since 2023-10-13
 */
@Slf4j
@RestController
@RequestMapping("/account")
public class AccountController {
	@RequestMapping("/add-account")
    public String myPage() {
        return "add-account"; // 返回逻辑视图名称
    }
	@PostMapping("/add")
    public ResponseEntity<String> addUser(@RequestBody Account account) {
        boolean success = account.insert();

        if (success) {
            return ResponseEntity.ok("Account added successfully");
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to add account");
        }
    }
    @Resource
    private AccountService accountService;

    @GetMapping("/code")
    public Result sendCode(@RequestParam("phone") String phone , HttpSession session) {
        return accountService.sendCode(phone , session);
    }

    @PostMapping("/signUp")
    public Result signUp(@RequestParam("phone") String phone , @RequestParam("code") String code ,
                         @RequestParam("password") String password ,
                         @RequestParam("passwords") String passwords ,
                         HttpSession session) {
        return accountService.signUp(phone , code , password , passwords , session);
    }


}



